package grib2db;

import test.LittleEndianDataInputStream;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;

public class grd2array {

	public float[] getArray(int x, String grdpath) {
		float[] data = new float[x];

		try {

			DataInputStream in = new DataInputStream(new BufferedInputStream(
					new FileInputStream(grdpath)));

			for (int i = 0; i < x; i++) {
				data[i] = in.readFloat();
			}

			in.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return data;
	}

	public float[][] getArray(int x, int y, String grdpath) {
		float[][] data = new float[x][y];
		try {
			LittleEndianDataInputStream in = new LittleEndianDataInputStream(
					new BufferedInputStream(new FileInputStream(grdpath)));

			for (int j = 0; j < y; j++) {
				for (int i = 0; i < x; i++) {
					data[i][j] = in.readFloat();
				}
			}
			in.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return data;
	}

	public float[][][] getArray(int x, int y, int z, String grdpath) {
		float[][][] a = new float[x][y][z];
		return a;
	}

	public float[][][][] getArray(int x, int y, int z, int v, String grdpath) {
		float[][][][] a = new float[x][y][z][v];
		return a;
	}

	public static void main(String[] args) {
		grd2array gy = new grd2array();
		float[] data1 = gy.getArray(3847392,
				"E:\\java_data_pre\\nc2grd\\uwnd.sig995.1948.nc.grd");
		float[][] data = gy.getArray(1280, 641,
				"E:\\java_data_pre\\grib2day\\cirl\\day\\123");
		// System.out.println(data[55][73]);
		// System.out.println(data[73][55]);
		// System.out.println(data[99][99]);
		System.out.println(data1[1]);
	}

}
